import logging


def check_ad_events(row):
    """
    检查部分广告位事件表，例如111、1112、110等
    :param row: df中的每一行的数据
    :return
    """
    # logging.info(f"第{row['NumId']}屏的{row['adId']}的请求为{row['18']}，类型是{type(row['18'])}、失败为{row['5']}，类型是{type(row['5'])}、"
    #              f"成功为{row['6']}，类型是{type(row['6'])}、跳过为{row['35']}，类型是{type(row['35'])}、展示为{row['0']}，类型是{type(row['0'])}")
    # 打印完整的row数据，以便调试
    # logging.info(f"完整的行数据: {row.to_dict()}")

    # 前提条件 18的数量=成功或失败的数量
    if row['18'] == row['6'] or row['18'] == row['5']:
        if row['18'] == row['35'] == row['0'] == row['26'] == row['1'] and row['6'] != 0:
            return "点击了adbutton"
        elif row['18'] == row['35'] == row['1'] and row['6'] != 0:
            return "点击了广告"
        elif row['18'] == row['0'] == row['35'] and row['35'] != 0 and row['6'] != 0:
            return "展示成功"
        elif row['18'] == row['5'] != 0 and row['6'] == 0:
            return "竞价失败"
        elif row['18'] == row['6'] == row['36'] != 0 and row['5'] == 0 and row['37'] == 0:
            return "页面隐藏"
        elif row['18'] == row['29'] == row['35'] and row['18'] != 0:
            return "展示失败"
        elif row['18'] == row['6'] == row['36'] == row['37'] == row['0'] != 0 and row['5'] == 0:
            return "未曝光后展示"
        elif row['18'] == row['6'] == row['35'] == row['37'] != 0 and row['5'] == 0:
            return "用户返回"
        elif row['18'] == row['6'] == row['36'] == row['0'] != 0 and row['5'] == 0:
            return "页面隐藏后再展示"
        else:
            # logging.info(f"完整的行数据: {row.to_dict()}")
            return "广告事件不正确"
    else:
        return "广告事件不不正确"


def check_pool_ad_events(row):
    """
    判断990、991
    :param
    row:
    :return:
    """
    # 前提条件 18的数量=成功或失败的数量
    if row['28'] == row['4'] or row['28'] == row['3']:
        # if row['35'] == row['0'] == row['26'] == row['1'] and row['6'] != 0:
        #     return "点击了adbutton"
        # elif row['35'] == row['35'] == row['1'] and row['6'] != 0:
        #     return "点击了广告"
        # elif row['35'] == row['0'] and row['35'] != 0 and row['6'] != 0 and row['29'] == 0:
        #     return "展示成功"
        if row['28'] == row['3'] != 0 and row['4'] == 0:
            return "请求失败"
        elif row['28'] == row['4'] != 0 and row['3'] == 0:
            return "请求成功"
        elif row['28'] == row['32'] == row['3'] != 0 and row['4'] == 0:
            return "广告超时"
        # elif row['28'] == row['32'] == row['3'] == row['0'] != 0 and row['5'] == 0:
        #     return "页面隐藏后再展示"
        else:
            return "广告事件不正确"
    else:
        return "广告事件不不正确"


def check_video_ad_events(row):
    """
    video
    :param
    row:
    :return:
    """
    # 前提条件 18的数量=成功或失败的数量
    if row['18'] == row['6'] or row['18'] == row['5']:
        # if row['35'] == row['0'] == row['26'] == row['1'] and row['6'] != 0:
        #     return "点击了adbutton"
        # elif row['35'] == row['35'] == row['1'] and row['6'] != 0:
        #     return "点击了广告"
        if row['6'] == row['0'] and row['18'] != 0 and row['5'] == row['2'] == 0:
            return "展示成功"
        elif row['18'] == row['5'] != 0 and row['6'] == 0:
            return "竞价失败"
        elif row['18'] == row['9'] == row['0'] == row['2'] != 0 and row['5'] == 0:
            return "播放完毕"
        elif row['18'] == row['2'] == row['0'] == row['10'] != 0 and row['5'] == 0:
            return "提前关闭"
        elif row['6'] == row['29'] != 0 and row['5'] == 0:
            # key[ADSDK], value[200|52|1677990|forbidden! video must be played in the foreground]
            return "展示失败"
        elif row['28'] == row['3'] != 0 and row['4'] == 0:
            return "缓存池请求失败"
        elif row['28'] == row['4'] != 0 and row['3'] == 0:
            return "缓存池请求成功"
        elif row['28'] == row['32'] == row['3'] != 0 and row['4'] == 0:
            return "广告超时"
        else:
            return "广告事件不正确"
    else:
        return "广告事件不不正确"
